/*
 * @Author: your name
 * @Date: 1970-01-01 08:00:00
 * @LastEditTime : 2019-12-25 21:23:28
 * @LastEditors  : Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /undefined/home/dy/linux/linux/WorkSpace/c/linux-c/learn/process/process-vfork.c
 */
#include<stdio.h> 
#include<unistd.h> 
 #include<stdlib.h>
int main()
{
    __uid_t ruid,euid,suid;
    if(-1 == getresuid(&ruid,&euid,&suid)){
        printf("error\n");
    }
    printf("ruid:%d,euid:%d,suid:%d\n",ruid,euid,suid);
   int a= setuid(getuid());
   printf("a:%d\n",a);
    pid_t pid = vfork();//创建进程
     a=0;
    if(pid == -1)
    {
        perror("fork error");
        return -1;
    }
    else if(pid == 0)//child
    {
        for(int i=0;i<10;i++){
            printf("%d ",i);
        }
        printf("i am a child:my pid is %d,my father is %d\n",getpid(),getppid());
        _exit(0);
    }
    else//father
    {
        printf("i am a father:my pid is %d\n",getpid()); 
    }
    setuid(getuid());
    printf("ruid:%d,euid:%d,suid:%d\n",ruid,euid,suid);

    return 0;

}